home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / xprzmodem_zedzap / xprzmodem.h < prev    next >
C/C++ Source or Header  |  1995-11-05  |  10KB  |  214 lines

  1. /**********************************************************************
  2.  *  xprzmodem.h: Definitions for xprzmodem.library;
  3.  *  Version 2.0, 28 October 1989, by Rick Huebner.
  4.  *  Released to the Public Domain; do as you like with this code.
  5.  *
  6.  *  Modified to support ZedZap/ZedZip fidonet protocol by
  7.  *  Yves Konighofer and Russel McOrmond.
  8.  *
  9.  *  Adapted to xprzmodem Version 2.52 by Andrea Cisternino (30 Nov 92)
  10.  **********************************************************************/
  11.  
  12. /* #define DEBUGLOG 1 */
  13.  
  14. /* Return codes */
  15. #define OK        0
  16. #define ERROR   (-1)
  17. #define TIMEOUT (-2)
  18. #define RCDO    (-3)
  19.  
  20. /* File Types... (NEW) */
  21. #define F_IS_FILEREQ   0
  22. #define F_IS_BINFILE   1
  23. #define F_IS_ARCFILE   2
  24. #define F_IS_MSGPACKET 3
  25. #define F_IS_ARCMAIL   4
  26.  
  27. /* Relevant control characters */
  28. #define CR     ('M' & 0x1F)   /* ^M */
  29. #define DLE    ('P' & 0x1F)   /* ^P */
  30. #define XON    ('Q' & 0x1F)   /* ^Q */
  31. #define XOFF   ('S' & 0x1F)   /* ^S */
  32. #define CAN    ('X' & 0x1F)   /* ^X */
  33. #define CPMEOF ('Z' & 0x1F)   /* ^Z */
  34.  
  35. /* Misc. program constants */
  36. #define LZMANAG           0   /* Default ZMODEM file management mode */
  37. #define LZTRANS           0   /* Default ZMODEM file transport mode */
  38. #define PATHLEN         256   /* What's the max legal path size? */
  39. #define CONFIGLEN        32   /* Max length of transfer options string */
  40. #define MINBLOCK         64   /* Min allowable packet size */
  41. #define MAXGOODNEEDED  8192   /* Max # good bytes req'd to bump packet size */
  42.  
  43. extern LONG KSIZE;
  44. extern LONG USEZERO;
  45. extern LONG NEWBAUD;
  46.  
  47. /* Provision for future 7-bit ZMODEM; for now, there's no difference */
  48. #define sendline xsendline
  49.  
  50. /*
  51.  * Replacement for global variables normally used, in order to make code
  52.  * fully reentrant; each invocation allocs their own Vars, and passes the
  53.  * struct pointer down through the entire program so they're always available.
  54.  * Pointer to this struct is usually able to be a register variable, so access
  55.  * is no worse than any stack variable (all register-relative).  Kinda
  56.  * kludgey, but the original ZModem code design depended on lots of globals,
  57.  * and I didn't want to redesign the whole damn thing.  Besides, it's more
  58.  * efficient than constantly pushing & popping args all over the place.
  59.  */
  60.  
  61. struct Vars
  62. {
  63.    struct XPR_IO io;          /* Copy of XProto IO struct passed by term prog. */
  64.    struct XPR_UPDATE __aligned xpru; /* Scratchpad xpr_update() control struct */
  65.    struct timeval __aligned Starttime; /* Time transfer started */
  66.    UBYTE __aligned Rxhdr [4]; /* Received header */
  67.    UBYTE Txhdr [4];           /* Transmitted header */
  68.    UBYTE Msgbuf [128];        /* Scratchpad buffer for printing messages */
  69.    UBYTE Filename [PATHLEN];  /* Name of the file being up/downloaded */
  70.    UBYTE Pktbuf [8192];       /* File data packet buffer */
  71.    UBYTE Modembuf [8192*2+256];    /* Input buffer for data from modem */
  72.    UBYTE Outbuf [8192*2+256]; /* Output buffer for data to modem */
  73.    UBYTE *Modemchar;          /* Next char to get from Modembuf */
  74.    UBYTE *Filebuf;            /* File I/O buffer address */
  75.    UBYTE *Filebufptr;         /* Current position within Filebuf */
  76.    long  File;                /* Handle of file being transferred */
  77.    long  Oldstatus;           /* Original terminal program's modem settings */
  78.    long  Baud;                /* BPS setting of modem */
  79.    long  Strtpos;             /* Starting byte position of transfer */
  80.    long  Fsize;               /* Size of file being transferred */
  81.    long  Rxbytes;             /* Number of bytes received so far */
  82.    long  Filebufpos;          /* File offset of data in Filebuf */
  83.    long  Filebufmax;          /* Size of Filebuf */
  84.    long  Filebuflen;          /* Number of bytes currently stored in Filebuf */
  85.    long  Filebufcnt;          /* Number of bytes remaining/written in Filebuf */
  86.    long  Rxpos;               /* Received file position */
  87.    long  Txpos;               /* Transmitted file position */
  88.    long  Filcnt;              /* Number of files opened for transmission */
  89.    long  Errcnt;              /* Number of files unreadable */
  90.    long  Noroom;              /* Flags 'insufficient disk space' errors */
  91.    long  Rxbuflen;            /* Largest frame they're willing to xfer */
  92.    long  Tframlen;            /* Largest frame we're willing to xfer */
  93.    long  Rxtimeout;           /* Tenths of seconds to wait for something */
  94.    long  Modemcount;          /* Number of bytes available in Modembuf */
  95.    long  Outbuflen;           /* Number of bytes currently stored in Outbuf */
  96.    long  Rxframeind;          /* ZBIN or ZHEX; type of frame received */
  97.    short Tryzhdrtype;         /* Header type to send corresponding to Last rx close */
  98.    short Txfcs32;             /* TRUE means send binary frame with 32 bit FCS */
  99.    short Rxflags;             /* Temp register */
  100.    short Wantfcs32;           /* want to send 32 bit FCS */
  101.    short Crc32t;              /* Display flag indicates 32 bit CRC being sent */
  102.    short Crc32;               /* Display flag indicates 32 bit CRC being recd */
  103.    short Rxtype;              /* Type of header received */
  104.    short Rxcount;             /* Count of data bytes received */
  105.    short Znulls;              /* Number of nulls to send at begin of ZDATA hdr */
  106.    short ErrorLimit;          /* How many sequential errors before abort */
  107.    char  Rxbinary;            /* Force binary mode download? */
  108.    char  Rxascii;             /* Force text mode download? */
  109.    char  Thisbinary;          /* Receive this file in binary mode? */
  110.    char  Lzconv;              /* Suggested binary/text mode for uploads */
  111.    char  Eofseen;             /* Text-mode EOF marker (^Z) rec'd on download? */
  112.    UBYTE Zconv;               /* ZMODEM file conversion request */
  113.    UBYTE Zmanag;              /* ZMODEM file management request */
  114.    UBYTE Ztrans;              /* ZMODEM file transport request */
  115.    UBYTE Lastsent;            /* Last text char written by putsec() */
  116.    UBYTE Lastzsent;           /* Last char sent by zsendline() */
  117.    UBYTE Fileflush;           /* Flush file I/O buffer before closing? */
  118.    UBYTE Attn[ZATTNLEN + 1];  /* Attention string rx sends to tx on err */
  119. };
  120.  
  121. /* Option settings and other variables needed outside of XProtocolSend/Receive;
  122.    separated from rest of Vars so that huge Vars struct doesn't have to be
  123.    allocated except during transfers.  Pointer to this struct kept in xpr_data. */
  124. struct SetupVars {
  125.   UBYTE *matchptr, *bufpos;
  126.   short buflen;
  127.   UBYTE option_t[2], option_o[2], option_b[8], option_f[8], option_e[8], option_s[4];
  128.   UBYTE option_r[4], option_a[4], option_d[4], option_k[4], option_c[8];
  129.   UBYTE option_m[8], option_n[4], option_p[256];
  130. };
  131.  
  132. /* Function prototypes */
  133.  
  134. long __saveds __asm XProtocolSend(register __a0 struct XPR_IO *xio);
  135. short getzrxinit(struct Vars *v);
  136. void  sendbatch(struct Vars *v);
  137. short sendone(struct Vars *v);
  138. short sendname(struct Vars *v);
  139. short zsendfile(struct Vars *v, short blen);
  140. short zsendfdata(struct Vars *v);
  141. short getinsync(struct Vars *v);
  142. void  saybibi(struct Vars *v);
  143.  
  144. long __saveds __asm XProtocolReceive(register __a0 struct XPR_IO *xio);
  145. short rcvbatch(struct Vars *v);
  146. short tryz(struct Vars *v);
  147. short rzfiles(struct Vars *v);
  148. short rzfile(struct Vars *v);
  149. short procheader(struct Vars *v);
  150. short putsec(struct Vars *v);
  151. void  ackbibi(struct Vars *v);
  152.  
  153. long __saveds __asm XProtocolSetup(register __a0 struct XPR_IO *xio);
  154. long __saveds __asm XProtocolCleanup(register __a0 struct XPR_IO *xio);
  155. long __saveds __asm XProtocolHostMon(
  156.                      register __a0 struct XPR_IO *xio,
  157.                      register __a1 char *serbuff,
  158.                      register __d0 long actual,
  159.                      register __d1 long maxsize);
  160. long __saveds __asm XProtocolUserMon(
  161.                      register __a0 struct XPR_IO *xio,
  162.                      register __a1 char *serbuff,
  163.                      register __d0 long actual,
  164.                      register __d1 long maxsize);
  165.  
  166. struct Vars *setup(struct XPR_IO *io);
  167. UBYTE *find_option(UBYTE *buf, UBYTE option);
  168. void  set_textmode(struct Vars *v);
  169. void  canit(struct Vars *v);
  170. void  zmputs(struct Vars *v, UBYTE *s);
  171. void  xsendline(struct Vars *v, UBYTE c);
  172. void  sendbuf(struct Vars *v);
  173. short readock(struct Vars *v, short tenths);
  174. char  char_avail(struct Vars *v);
  175. void  update_rate(struct Vars *v);
  176. long  bfopen(struct Vars *v, UBYTE *mode);
  177. void  bfclose(struct Vars *v);
  178. void  bfseek(struct Vars *v, long pos);
  179. long  bfread(struct Vars *v, UBYTE *buf, long length);
  180. long  bfwrite(struct Vars *v, UBYTE *buf, long length);
  181. void  ioerr(struct XPR_IO *io, char *msg);
  182. void  upderr(struct Vars *v, char *msg);
  183. void  updmsg(struct Vars *v, char *msg);
  184. void  updstatus(struct Vars *v,char *filename,long status);
  185. long  getfree(void);
  186. char  exist(struct Vars *v);
  187. int   mysprintf(char *buffer, char *ctl, ...);
  188.  
  189. #ifdef DEBUGLOG
  190. void  dlog(struct Vars *v, UBYTE *s);
  191. #endif
  192.  
  193. void  zsbhdr(struct Vars *v, USHORT type);
  194. void  zshhdr(struct Vars *v, USHORT type);
  195. void  zsdata(struct Vars *v, short length, USHORT frameend);
  196. short zrdata(struct Vars *v, UBYTE *buf, short length);
  197. short zrdat32(struct Vars *v, UBYTE *buf, short length);
  198. short zgethdr(struct Vars *v);
  199. short zrbhdr(struct Vars *v);
  200. short zrbhdr32(struct Vars *v);
  201. short zrhhdr(struct Vars *v);
  202. void  zputhex(struct Vars *v, UBYTE c);
  203. void  zsendline(struct Vars *v, UBYTE c);
  204. short zgethex(struct Vars *v);
  205. short zdlread(struct Vars *v);
  206. short noxrd7(struct Vars *v);
  207. void  stohdr(struct Vars *v, long pos);
  208. long  rclhdr(struct Vars *v);
  209.  
  210. extern ULONG UnixTimeOffset;
  211. ULONG getsystime(struct timeval *tv);
  212.  
  213. /* End of XprZmodem.h source */
  214.